package com.snopy.scheduler;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @author snopy
 * @version 1.0.0
 * @classname DemoTask
 * @description
 * @email 77912204@qq.com
 * @date 2022/12/09 12:50
 */
@Slf4j

public class DemoTask {
    public static void main(String[] args) {

        try {
            DateBuilder dateBuilder = DateBuilder.newDate().atHourMinuteAndSecond(14,0,0);

            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            scheduler.start();

            JobDetail job = newJob(HelloJob.class)
                            .withIdentity("job1","group1")
                            .usingJobData("job1Says","Hello World!")
                            .usingJobData("myFloatValue",3.1415926f)
                            .withIdentity("job2","group2")
                            .usingJobData("job2Says","Thanks")
                            .build();
            JobDetail job2 = newJob(HelloJob.class)
                    .withIdentity("job3","group1")
                    .usingJobData("job3Says","Thanks Job3")
                    .build();
            TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
            SimpleTrigger simpleTrigger = triggerBuilder
                    .withDescription("this is a test trigger.")
                    .withIdentity("trigger1", "group2")
                    .startNow()
                    .withSchedule(simpleSchedule()
                            .withIntervalInSeconds(5).repeatForever())
                    .build();
            scheduler.scheduleJob(job,simpleTrigger);
            scheduler.scheduleJob(job2,simpleTrigger);

            //scheduler.shutdown();
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        }
    }
}
